$(function () {
    $("#page").load("/html/page.html");
});

function findAll() {
    let data = {
        word: $("#word").val()
        , translate: $("#translate").val()
        , submitter: localStorage.getItem("username")
        , pageNum: $.trim($("#pageNum").val())
        , pageSize: $.trim($("#pageSize").val())
    }
    let result = myAjax('/w/word/mySubmit', 'post', data);
    console.log(result);
    if (result.code === 200) {
        showSubmit(result.data.list);
        $("#pageCount").html(result.data.number);
    } else {
        alert("服务器开小差了");
    }
}

function showSubmit(data) {
    let html = '';
    for (let i = 0; i < data.length; i++) {
        html += '   <tr> ' +
            '  <td><input type="checkbox" name="isCheck" value="' + data[i].id + '">' + data[i].id + '</td>\n' +
            '        <td>' + data[i].word + '</td>\n' +
            '        <td>' + data[i].translate + '</td>\n' +
            '        <td>' + data[i].subTime + '</td>\n' +
            '        <td>' + data[i].heat + '</td>\n' +
            '        <td>  <button type="button" onclick="edit(' + data[i].id + ')" ' +
            'class="layui-btn  layui-btn-sm"><i class="">修改</i></button></td>' +
            '    </tr>';
    }
    $("#findAll").html(html);
}

function edit(id) {
    sessionStorage.setItem("wordId",id);
    //弹出一个页面层
    layer.open({
        type: 2,
        anim:3,
        title:'修改提交',
        area: ['600px', '500px'],
        shadeClose: true, //点击遮罩关闭
        content: ['/html/word/editSub.html','no'],
    })
}
layui.use("layer");
function newSub() {
    //弹出一个页面层
    layer.open({
        type: 2,
        anim:3,
        title:'提交单词',
        area: ['600px', '500px'],
        shadeClose: true, //点击遮罩关闭
        content: ['/html/word/newSubmitWord.html','no'],
    })
}